package com.vajava.str.model;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Entity(name = "Batch")
public class Batch {
    private Long id;
    private TestType type;
    private Date timestamp;
    private Build build;

    private static final List<String> EQHA_IGNORE = Arrays.asList("id");

    public Batch(Build build, TestType type, Date timestamp) {
        this.build = build;
        this.type = type;
        this.timestamp = timestamp;
    }

    protected Batch() {
    }

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @ManyToOne(optional = false, targetEntity = TestType.class)
    public TestType getType() {
        return type;
    }

    public void setType(TestType type) {
        this.type = type;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    @ManyToOne(optional = false, targetEntity = Build.class)
    public Build getBuild() {
        return build;
    }

    public void setBuild(Build build) {
        this.build = build;
    }

    public boolean equals(Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj, EQHA_IGNORE);
    }

    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this, EQHA_IGNORE);
    }

    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
